Detect and Decode QR Code in Image using OpenCV

您所在的位置:网站首页 graycodepattern decode opencv Detect and Decode QR Code in Image using OpenCV

Detect and Decode QR Code in Image using OpenCV

2024-07-08 09:53| 来源: 网络整理| 查看: 265

QR code is a two-dimensional barcode which stores encoded data. It can be a website URL, contact details, location coordinates, email address, plain text, etc. QR code can store more data than a linear barcode of equal size.

This tutorial provides an example how to detect and decode a QR code in an image using OpenCV.

We create an object of class QRCodeDetector. QR code is detected and decoded by using the detectAndDecode method. It allows getting decoded data and an array of vertices of the found QR code.

import cv2 img = cv2.imread('test.jpg') decoder = cv2.QRCodeDetector() data, points, _ = decoder.detectAndDecode(img) if points is not None: print('Decoded data: ' + data) points = points[0] for i in range(len(points)): pt1 = [int(val) for val in points[i]] pt2 = [int(val) for val in points[(i + 1) % 4]] cv2.line(img, pt1, pt2, color=(255, 0, 0), thickness=3) cv2.imshow('Detected QR code', img) cv2.waitKey(0) cv2.destroyAllWindows() #include #include using namespace cv; int main() { Mat img = imread("test.jpg"); QRCodeDetector decoder = QRCodeDetector(); std::vector points; std::string data = decoder.detectAndDecode(img, points); if (!points.empty()) { std::cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3